package struts.tools;

import struts.DataElement;
import struts.Text;
import struts.TextType;

public class Validation {

	public String generateTest(DataElement elt){
		String labelID=WebSiteData.generateLabelID();
		
		if(elt instanceof Text){
			Text text=(Text)elt;	//le nom du Contact est obligatoire
			
			if(text.getType()==TextType.EMAIL){
				WebSiteData.addRessource(labelID, "le "+elt.getName()+" du Contact est obligatoire");
				return "if( get"+elt.getName()+"()== null || get"+elt.getName()+"().length() < 1 ) {\n"+
				"errors.add("+elt.getName()+",new ActionMessage(\""+labelID+"\"));"+
		      "\n}";
				
			}else if(text.getType()==TextType.SIMPLE_TEXT){
				WebSiteData.addRessource(labelID, "le "+elt.getName()+" du Contact est obligatoire");
				return "if( get"+elt.getName()+"()== null || get"+elt.getName()+"().length() < 1 ) {\n"+
				"errors.add("+elt.getName()+",new ActionMessage(\""+labelID+"\"));"+
		      "\n}";
				
			}else if(text.getType()==TextType.PASSWORD){
				WebSiteData.addRessource(labelID, "le "+elt.getName()+" du Contact est obligatoire");
				return "if( get"+elt.getName()+"()== null || get"+elt.getName()+"().length() < 1 ) {\n"+
				"errors.add("+elt.getName()+",new ActionMessage(\""+labelID+"\"));"+
		      "\n}";
			}
			
		}
		
		
		return "";
	}
}
